﻿<?php 
//error_reporting(0);

include 'conn.php';
include 'common.php';?>
<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>考试查询</title>
<body>
<div class="container">
<div class="nav_header">
<?php include 'head.php';?>
</div>
<div class="main_cj_content">
<script type="text/javascript">
function delete_check()
{
	var returnVal = window.confirm("考试删除将无法恢复,并且会删除本次考试所有的成绩\n是否继续？", "提示");
	if(returnVal) {
	   return true;  
	}
	return false;
}
</script>
<?php

echo "<p class='welcome'>查找结果:</p><hr><br />";
if($_GET['exam_name'])
{
	$exam_name=getget('exam_name');
	$exe="select * from exams where exam_description like '%".$exam_name."%'";
	$rs=mysql_query($exe);
	//因php版本问题有的不支持mysql_fetch_array($rs)判断是否含返回值，对于这些版本用以下代码：
	$count_exe="select count(*) from exams where exam_description like '%".$exam_name."%'";
	$count_rs=mysql_query($count_exe);
	$row=mysql_fetch_array($count_rs);
	$row_count=$row['count(*)'];
	if($row_count>0)
	//echo $row_count;
	//if(mysql_fetch_array($rs))
   {
   	echo "<table border=1 class='search_result'><tr><td>考试ID</td><td>考试名称</td><td>考试日期</td><td>考试类别</td><td>考试详情</td><td>删除考试</td></tr>";
   	//echo "<tr><td>$exam_id</td><td>$exam_name</td><td>$exam_date</td><td>$exam_category</td></td>";
   	$rs1=mysql_query($exe);
   	while ($row=mysql_fetch_array($rs1))
   	{
   		$exam_name=$row['exam_description'];
   		switch ($row['exam_category'])
   		{
   			case 1:
   				$exam_category="全校统考";
   				 
   				break;
   			case 2:
   				$exam_category="班级考试";
   				break;
   			case 3:
   				$exam_category="全县统考";
   				break;
   		}
   		$exam_date=$row['exam_date'];
   		$exam_id=$row['id'];
   		 
   		echo "<tr><td>$exam_id</td><td>$exam_name</td><td>$exam_date</td><td>$exam_category</td><td><a href='exam_detail.php?examid=$exam_id'>详情</a></td><td><form action='exam_delete.php'  method='post' >
<input type='hidden' name='examid' id='examid' value='$exam_id' />
<input type='submit' value='删除'  onclick='return delete_check()'/></form></td></tr>";
   	}
   	echo "</table>";
   }

   else 
   echo "<p>对不起！没有您查询的考试！</p>";
}
else 
{
	$exe="select * from exams";
	$rs=mysql_query($exe);

	$count_exe="select count(*) from exams";
	$count_rs=mysql_query($count_exe);
	$row=mysql_fetch_array($count_rs);
	$row_count=$row['count(*)'];
	if($row_count>0)
//	if(mysql_fetch_array($rs))
	{
		echo "<table border=1 class='search_result'><tr><td>考试ID</td><td>考试名称</td><td>考试日期</td><td>考试类别</td><td>考试详情</td><td>删除考试</td></tr>";
		//echo "<tr><td>$exam_id</td><td>$exam_name</td><td>$exam_date</td><td>$exam_category</td></td>";
		$rs1=mysql_query($exe);
		while ($row=mysql_fetch_array($rs1))
		{
			$exam_name=$row['exam_description'];
			switch ($row['exam_category'])
			{
				case 1:
					$exam_category="全校统考";
	
					break;
				case 2:
					$exam_category="班级考试";
					break;
				case 3:
					$exam_category="全县统考";
					break;
			}
			$exam_date=$row['exam_date'];
			$exam_id=$row['id'];
	
			echo "<tr><td>$exam_id</td><td>$exam_name</td><td>$exam_date</td><td>$exam_category</td><td><a href='exam_detail.php?examid=$exam_id'>详情</a></td><td><form action='exam_delete.php'  method='post' >
<input type='hidden' name='examid' id='examid' value='$exam_id'/>
<input type='submit' value='删除'  onclick='return delete_check()'/></form></td></tr>";
		}
		echo "</table>";
}
else {
echo "<p>对不起！暂时没有登记任何考试！</p>";
}
}
?>
</div>
</div>
</body>
</html>
